/*
Date: October 2025
Project: Income and Child Maltreatment: Evidence from a Discontinuity in Tax Benefits
Author: Katherine Rittenhouse
Purpose: Create Figure A1a-d
*/

clear all
set more off

***Taxsim sample datasets***

set obs 1001
gen taxsimid = _n
gen year = 2010
gen state = 5
gen mstat = 1
gen page = 30
gen sage = 0
gen depx = 1
gen dep13 = 1
gen dep17 = 1
gen dep18 = 1
gen pwages = (_n-1)*100
gen swages = 0

save "fortaxsim.dta",replace
* run through taxsim 
taxsim32,full 

shell ren "taxsim_out.dta" "single2010_1ch.dta"

use "fortaxsim.dta",clear
replace depx=0
replace dep13 = 0
replace dep17 = 0
replace dep18 = 0
taxsim32,full 
shell ren "taxsim_out.dta" "single2010_noch.dta"

use "single2010_noch.dta", clear

foreach var of varlist _all {
	ren `var' `var'noch
}
ren taxsimidnoch taxsimid 

merge 1:1 taxsimid using "single2010_1ch.dta"
drop _m
merge 1:1 taxsimid using fortaxsim.dta
drop _m

gen valuesingle = (fiitaxnoch+siitaxnoch) - (fiitax + siitax)
gen sharesingle = valuesingle/(pwages - fiitax - siitax)
gen refundablevaluesingle = eitcvaluesingle+ctcvaluesingle
gen refundablesharesingle = refundablevaluesingle/(pwages - fiitax - siitax)

keep *single taxsimid pwages 
save "values.dta",replace


***married
use "fortaxsim.dta",clear
replace mstat = 2
taxsim32,full 
shell ren "taxsim_out.dta" "married2010_1ch.dta"

use "fortaxsim.dta",clear
replace depx=0
replace dep13 = 0
replace dep17 = 0
replace dep18 = 0
replace mstat = 2

taxsim32,full 
shell ren "taxsim_out.dta" "married2010_noch.dta"

use "married2010_noch.dta", clear

foreach var of varlist _all {
	ren `var' `var'noch
}
ren taxsimidnoch taxsimid 

merge 1:1 taxsimid using "married2010_1ch.dta"
drop _m
merge 1:1 taxsimid using fortaxsim.dta
drop _m

gen valuemarried = (fiitaxnoch+siitaxnoch) - (fiitax + siitax)
gen sharemarried = valuemarried/(pwages - fiitax - siitax)
gen refundablevaluemarried = eitcvaluemarried+ctcvaluemarried
gen refundablesharemarried = refundablevaluemarried/(pwages - fiitax - siitax)
keep *married taxsimid pwages 
merge 1:1 taxsimid using "values.dta"

twoway  (line valuesingle pwages, color(black)) (line valuemarried pwages, color(black) lpattern(dash) xtitle("Wage income ($)") ytitle("Tax value ($)") legend(order(1 "Single" 2 "Married"))), scheme(s1color) 
graph export "taxvalue2010.pdf", as(pdf) replace


twoway  (line sharesingle pwages, color(black)) (line sharemarried pwages, color(black) lpattern(dash) xtitle("Wage income ($)") ytitle("Tax value (% of after-tax income)") legend(order(1 "Single" 2 "Married"))), scheme(s1color) 
graph export "taxshare2010.pdf", as(pdf) replace

twoway  (line refundablevaluesingle pwages, color(black)) (line refundablevaluemarried pwages, color(black) lpattern(dash) xtitle("Wage income ($)") ytitle("Refundable tax value ($)") legend(order(1 "Single" 2 "Married"))), scheme(s1color) 
graph export "refundablevalue2010.pdf", as(pdf) replace

twoway  (line refundablesharesingle pwages, color(black)) (line refundablesharemarried pwages, color(black) lpattern(dash) xtitle("Wage income ($)") ytitle("Refundable tax value (\% of after-tax income)") legend(order(1 "Single" 2 "Married"))), scheme(s1color) 
graph export "refundableshare2010.pdf", as(pdf) replace
